package collection1;

import java.text.CollationKey;
import java.text.Collator;
import java.util.*;

/** 集合排序---point对象*/
public class SortPoint {
    public static void main(String[] args) {
        List<point1> list = new ArrayList<>();
        list.add(new point1(5,8));
        list.add(new point1(15, 60));
        list.add(new point1(57,89));
        list.add(new point1(1,4));
        list.add(new point1(10,12));
        list.add(new point1(22,35));
        System.out.println("list:"+list);

        Collections.sort(list, new Comparator<point1>() {
            @Override
            public int compare(point1 o1, point1 o2) {
                int len1 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
                int len2 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
                return len2-len1;//降序
                //return len1-len2;//升序
            }
        });

        Collections.sort(list,(o1,o2) ->{
            int len1 = o1.getX()*o1.getX()+o1.getY()*o1.getY();
            int len2 = o2.getX()*o2.getX()+o2.getY()*o2.getY();
            return len2-len1;
        });


        list.sort(new Comparator<point1>() {
            @Override
            public int compare(point1 o1, point1 o2) {
                return o1.getX()-o2.getY();
            }
        });
        System.out.println("list:"+list);





    }
}
